package top.likeqc.leetcode.editor.cn;

/**
 * @see <a href="https://leetcode.cn/problems/largest-plus-sign/">764. 最大加号标志</a>
 */
public class LargestPlusSign {
    public static void main(String[] args) {
        Solution solution = new LargestPlusSign().new Solution();
        int[][] a = new int[][] {{1, 2}};
        solution.orderOfLargestPlusSign(5, a);
    }
    // leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int orderOfLargestPlusSign(int n, int[][] mines) {
            int[][] grid = new int[n][n];
            int k = 0;

            for (int i = 0; i < mines.length; i++) {
                grid[mines[i][0]][mines[i][1]] = 1;
            }

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (grid[i][j] == 0) {
                        int t = j;
                        // 上
                        int up = 1;
                        while (--t >= 0 && grid[i][t] == 0) {
                            up++;
                        }
                        // 下
                        t = j;
                        int down = 1;
                        while (++t < n && grid[i][t] == 0) {
                            down++;
                        }
                        // 左
                        t = i;
                        int left = 1;
                        while (--t >= 0 && grid[t][j] == 0) {
                            left++;
                        }
                        // 右
                        t = i;
                        int right = 1;
                        while (++t < n && grid[t][j] == 0) {
                            right++;
                        }
                        int currentMinK = Math.min(up, Math.min(down, Math.min(left, right)));
                        k = Math.max(k, currentMinK);
                    }
                }
            }

            return k;
        }
    }
    // leetcode submit region end(Prohibit modification and deletion)

}
